<style>
  .layui-table-cell .layui-table-sort {
    display: none;
  }
</style>

<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt">
                <div class="layui-inline">
                  <label class="layui-form-label">产品类别：</label>
                  <div class="layui-input-inline">
                    <input id="productTypeId" type="hidden" name="productTypeId" />
                    <div id="productType"></div>
                  </div>
                </div>
                <!-- 客户名称 -->
                <div class="layui-inline">
                  <label class="layui-form-label">客户名称：</label>
                  <div class="layui-input-inline">
                    <select id="customerId_search" name="customerId_search" lay-filter="reviewPostId" class="common-select-search"></select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">客户产品编码：</label>
                  <div class="layui-input-inline">
                    <input name="customerProCode" id="customerProCode" class="layui-input" type="text" placeholder="请输入产品编码" autocomplete="off" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">产品状态状态：</label>
                  <div class="layui-input-inline">
                    <select name="productStatus" lay-filter="productStatus" class="common-select-search">
                      <option value="">状态</option>
                      <option value="1">待规划</option>
                      <option value="2">工程规划中</option>
                      <option value="3">已定型</option>
                    </select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">客户产品图号：</label>
                  <div class="layui-input-inline">
                    <input name="customerProFigure" id="customerProFigure" class="layui-input" type="text" placeholder="请输入图号" autocomplete="off" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">交货时间：</label>
                  <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="givenStartTimed" placeholder="交货时间" />
                  </div>
                </div>
              </div>
              <div class="query-rt">
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                  <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <table class="layui-table" id="productTaskTableInfo" lay-filter="productTaskTableInfo"></table>
    </div>
  </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="productPlanningTableBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
  <!-- <a class="layui-btn layui-btn-xs" lay-event="planning">产品规划</a> -->

  <!-- {{# if(d.productStatus=='待规划'){ }} -->
  <!-- <a class="layui-btn layui-btn-xs" lay-event="planning">产品规划</a> -->
  <!-- {{# } }} -->
</script>

<!-- js部分 -->
<script>
  layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'laytpl', 'tableTreeDj', 'config'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var laydate = layui.laydate;
    var table = layui.table;
    var form = layui.form;
    var config = layui.config;
    var admin = layui.admin;
    var tableTree = layui.tableTreeDj;

    laydate.render({
      elem: '#givenStartTimed',
      format: 'yyyy-MM-dd',
      range: '至',
    });

    // 渲染表格
    var insTb = table.render({
      id: 'productTaskTableInfo',
      elem: '#productTaskTableInfo',
      // url: config.base + 'enterprise/res/admin/planning/proTask/list',
      url: config.base + 'enterprise/res/admin/bomPlanRecord/list',
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          { type: 'numbers', title: '序号', fixed: 'left' },
          { title: '规划记录ID', field: 'code' },
          { title: '产品编号', field: 'cusProductCode' },
          { title: '内部产品名称', field: 'cusProductName' },
          // { title: '产品图号', field: 'productDrawingNo' },
          { title: '性质', field: 'productNature' },
          { title: '属性', field: 'assemblyNature' },
          { title: '物资类别', field: 'cusProductType' },
          // { title: '评审记录编号', field: 'reviewRecordNo' },
          { title: '所属订单编号', field: 'orderCode' },
          { title: '计划交货时间', field: 'givenPlanningTime' },
          // { title: '状态', field: 'status' },
          // { title: '创建人', field: 'creator' },
          { title: '创建时间', field: 'createTime' },
          { align: 'center', toolbar: '#productPlanningTableBar', title: '操作', width: 220 },
        ],
      ],
      done: function (res, curr, count) {},
    });


    //初始化产品类别
    admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getTreeData', { limit: 99999 }, 'productType', null, '产品类别', 'productTypeId', function (row) {
      $("input[name='productTypeId']").val(row.arr[0].value);
    });

    //部门列表
    // admin.initDataSelectTree(true, 'user/admin/role/getTreeData', null, 'departmentSearchClaim', null, "部门", "departmentSearchClaimId", function (data) {
    //     // 获取部门ID
    //     let departmentId = data.change[0].value;
    //     //赋值部门id
    //     $('#departmentSearchClaimId').val(data.change[0].value);
    //     $('#reviewPostId').empty();
    //     //部门下的岗位列表
    //     admin.initDataSelect("user/admin/role/getPostData", {roleId: departmentId}, "reviewPostId", null, "岗位", null, null);
    // });

    //渲染下拉
    form.render('select');

    // 工具条点击事件
    table.on('tool(productTaskTableInfo)', function (obj) {
      var data = obj.data;
      if (obj.event === 'edit') {
        //修改
        showEditModel(data);
      } else if (obj.event === 'detail') {
        //详情
        showDetailModel({...data, id: data.taskId}, '1');
      } else if (obj.event === 'cancellation') {
        //作废
        console.log('作废...');
      } else if (obj.event === 'planning') {
        //产品规划
        showProductBuilder(data);
      }
    });

    // 搜索
    form.on('submit(formSubSearchLog)', function (data) {
      data.field.givenStartTimed = $('#givenStartTimed').val();
      insTb.reload({ where: data.field, page: { curr: 1 } }, 'data');
    });

    // 重置搜索
    form.on('submit(resets)', (data) => {
      insTb.reload({ where: admin.resetSearch(data.field), page: { curr: 1 } }, 'data');
    });

    // 添加按钮点击事件
    $('#productPlanningAdd').click(function () {
      showAddModel();
    });

    //添加自研任务
    $('#productPlanningZYAdd').click(function () {
      showEditZYModel();
    });

    // 显示编辑弹窗
    function showAddModel() {
      let title = '添加客户研发信息';
      admin.formOpen({
        type: 1,
        area: ['1680px', '90%'],
        style: 'font-size: 20px;',
        title: title,
        path: 'components/res/planning/taskAddFrom.html',
        finish: function () {
          table.reload(insTb, {});
        },
      });
    }

    // 显示编辑弹窗
    function showEditModel(data) {
      let title = '';
      let path = '';
      if (data.source === '客户订单') {
        admin.putTempData('resProTaskData', data ? data : null);
        title = '修改客户研发信息';
        path = 'components/res/planning/taskUpdateFrom.html';
      } else {
        admin.putTempData('resProTaskZYData', data ? data : null);
        title = '修改自研产品信息';
        path = 'components/res/planning/taskZYUpdateFrom.html';
      }
      admin.formOpen({
        type: 1,
        area: ['1680px', '90%'],
        style: 'font-size: 20px;',
        title: title,
        path: path,
        finish: function () {
          table.reload(insTb, {});
        },
      });
    }

    // 显示编辑弹窗
    function showEditZYModel() {
      let title = '添加自研任务';
      admin.formOpen({
        area: ['1680px', '90%'],
        style: 'font-size: 20px;',
        title: title,
        path: 'components/res/planning/taskAddZYFrom.html',
        finish: function () {
          table.reload(insTb, {});
        },
      });
    }

    //产品规划
    function showProductBuilder(data) {
      let title = '';
      let path = '';
      if (data.source === '客户订单') {
        admin.putTempData('resProTaskData', data ? data : null);
        title = '客户产品规划管理';
        path = 'components/res/planning/taskProductBuilderFrom.html';
      } else {
        admin.putTempData('resProTaskZYData', data ? data : null);
        title = '自研产品规划管理';
        path = 'components/res/planning/taskProductZYBuilderFrom.html';
      }
      admin.formOpen({
        type: 1,
        area: ['1580px', '90%'],
        style: 'font-size: 20px;',
        title: title,
        path: path,
        finish: function () {
          table.reload(insTb, {});
        },
      });
    }

    //显示详情
    function showDetailModel(data) {
      let title = '';
      let path = '';
      if (data.source === '客户订单') {
        admin.putTempData('resProTaskData', data ? data : null);
        title = '客户产品规划详情';
        path = 'components/res/planning/bomPlan/taskProductBuilderFrom.html';
      } else {
        admin.putTempData('resProTaskZYData', data ? data : null);
        title = '自研产品规划详情';
        path = 'components/res/planning/bomPlan/taskProductZYBuilderFrom.html';
      }
      admin.formOpen({
        type: 1,
        area: ['1580px', '90%'],
        style: 'font-size: 20px;',
        title: title,
        path: path,
        finish: function () {
          table.reload(insTb, {});
        },
        success:function(){
          parentData.type = 'bom';
          parentData.eventName = 'detail';
        }
      });
    }
  });
</script>

